define(["jquery"],function(){
	return{
		
		init : function(){
			this.getData();
		},
		
		getData : function(){
			var that = this;
			$.ajax({
				type:"get",
				url:"data_json/data_lenovo.json",
				async:true,
				success:function(res){
					$.each(res, function(index,item) {
						if(index != res.length-1){
							that.lenovoShow(item,0);
						}else{
							console.log("执行了,最后一条数据")
							that.lenovoShow(item,1);
						}
					});
				}
			});
			
		},
		
		lenovoShow : function(res,type){
			
			
			if(type == 0){
				var lenovo = $('<div class="common_container"></div>');
				var html = `<div class="common_con">
					<h3>${res.title}</h3>
					<ul class="common_more">
						${moreShow(res.moreItems)}
					</ul>
					<div class="common_main">
						<div class="common_main_left">
							<a href="javascript:;"><img src="https://p1.lefile.cn/product/adminweb/2017/09/06/c05de2e6-c8ad-4014-af4d-b3f6adb427ad.jpg"/></a>
						</div>
						<ul class="common_main_right">
						
							${rightItemShow(res.rightItems)}	
						</ul>
					</div>
				</div>`
			}else{
				var lenovo = $('<div id="social" class="common_container"></div>');
				var html = `<div class="social">
					<h3>${res.title}</h3>
					<ul class="social_container">
						${itemShow(res.items)}
					</ul>
				</div>`
			}
			
			lenovo.html(html);
			$("#footer").before(lenovo);
			bindEvent();
			
			
			function itemShow(res){
				var html = "";
				$.each(res, function(index,item) {
					html += `<li class="social_item">
							<a href=""><img src="${item.src}"/></a>
							<p class="item_bottom">
								<span class="bottom_left">
									${item.bottom_left}
								</span>
								<span class="bottom_right">
									${item.bottom_right}
								</span>
							</p>
						</li>`
				});
				return html;
			}
			
			//绑定事件
			function bindEvent(){
				
				$(".right_item").on("mouseenter",function(){
					
					$(this).find(".item_img").stop().animate({
						left:"47.5px"
					},500);
				}).on("mouseleave",function(){
					$(this).find(".item_img").stop().animate({
						left:"37.5px"
					},500);
				});
			}
			
			function moreShow(res){
				var html = "";
				$.each(res, function(index,item) {
					html += `<li><a href="javascript:;">${item}</a></li>`;
				});
				html += `<li><a href="javascript:;" class="iconfont">更多&nbsp;</a></li>`;
				return html;
			}
			
			function rightItemShow(res){
				var html = "";
				$.each(res, function(index,item) {
					html += `<li class="right_item">
							<a href="javascript" class="item_img_container"><img class="item_img" src="${item.src}"/></a>
							<p class="item_name"><a href="javascript:;" title="${item.name}">${item.name}</a></p>
							<p class="item_introduce"><a href="javascript:;">${item.introduce}</a></p>
							<p class="item_price"><a href="javascript:;">￥${item.price}</a></p>
							<span class=""></span>
						</li>`;
				});
				
				return html;
			}
		}
		
		
		
		
		
		
		
		
		
		
	}
})




